/*
 * Copyright 2009 SHOP.COM
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.shop.opensocial.mediated.shindig.factories;

import com.shop.opensocial.mediated.types.CollectionOptionsMediator;
import org.apache.shindig.protocol.model.FilterOperation;
import org.apache.shindig.protocol.model.SortOrder;
import org.apache.shindig.social.opensocial.spi.CollectionOptions;

/**
 * Factory for converting between Mediator type and Shindig type
 *
 * @author Jordan Zimmerman
 */
public class CollectionOptionsMediatorFactory extends GenericMediatorFactory<CollectionOptions, CollectionOptionsMediator>
{
	public static final GenericMediatorFactory<CollectionOptions, CollectionOptionsMediator>		i = new CollectionOptionsMediatorFactory();

	@Override
	protected CollectionOptions internalMake(CollectionOptionsMediator c)
	{
		CollectionOptions o = new CollectionOptions();
		o.setFilter(c.getFilter());
		o.setFilterOperation(fFilterOperationMapper.from(c.getFilterOperation()));
		o.setFilterValue(c.getFilterValue());
		o.setFirst(c.getFirst());
		o.setMax(c.getMax());
		o.setSortBy(c.getSortBy());
		o.setSortOrder(fSortOrderMapper.from(c.getSortOrder()));
		o.setUpdatedSince(c.getUpdatedSince());
		return o;
	}

	@Override
	protected CollectionOptionsMediator internalUnmake(CollectionOptions c)
	{
		return new CollectionOptionsMediator(c.getSortBy(), fSortOrderMapper.to(c.getSortOrder()), c.getFilter(), fFilterOperationMapper.to(c.getFilterOperation()), c.getFilterValue(), c.getFirst(), c.getMax(), c.getUpdatedSince());
	}

	private CollectionOptionsMediatorFactory()
	{
	}

	private static final EnumMapper<SortOrder, CollectionOptionsMediator.SortOrder> 				fSortOrderMapper = new EnumMapper<SortOrder, CollectionOptionsMediator.SortOrder>(SortOrder.values(), CollectionOptionsMediator.SortOrder.values());
	private static final EnumMapper<FilterOperation, CollectionOptionsMediator.FilterOperation>	fFilterOperationMapper = new EnumMapper<FilterOperation, CollectionOptionsMediator.FilterOperation>(FilterOperation.values(), CollectionOptionsMediator.FilterOperation.values());
}
